home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / exp.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  1KB  |  52 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "pml.h"
  4. #include "cordic.h"
  5.  
  6. static char     funcname[] = "exp";
  7.  
  8. extern CORDIC_Table CORDIC_Table0[];
  9. extern CORDIC_Table CORDIC_Table1[];
  10.  
  11. double
  12. exp(x)
  13.     double          x;
  14. {
  15.     double          t, y, z;
  16.     double          x0, y0, z0;
  17.     double          D, temp;
  18.     int             Q;
  19.     struct exception xcpt;
  20.  
  21.     if (x > LOGE_MAXDOUBLE) {
  22.         xcpt.type = OVERFLOW;
  23.         xcpt.name = funcname;
  24.         xcpt.arg1 = x;
  25.         if (!matherr(&xcpt)) {
  26.             fprintf(stderr, "%s: OVERFLOW error\n", funcname);
  27.             errno = ERANGE;
  28.             xcpt.retval = MAXDOUBLE;
  29.         }
  30.     }
  31.     else if (x <= LOGE_MINDOUBLE) {
  32.         xcpt.type = UNDERFLOW;
  33.         xcpt.name = funcname;
  34.         xcpt.arg1 = x;
  35.         if (!matherr(&xcpt)) {
  36.             fprintf(stderr, "%s: OVERFLOW error\n", funcname);
  37.             errno = ERANGE;
  38.             xcpt.retval = 0.0;
  39.         }
  40.     }
  41.     else {
  42.         t = x / LN2;
  43.         D = modf(t, &temp);
  44.         Q = temp;
  45.         x0 = y0 = 1.0;
  46.         z0 = D * LN2;
  47.         CORDIC_rotate1(1, CORDIC_Table1, &x0, &y0, &z0);
  48.         xcpt.retval = ldexp(x0 / CORDIC_Table1->kval, Q);
  49.     }
  50.     return (xcpt.retval);
  51. }
  52.